var {
  getEventInfo,
} = require('../../utils/api');
const methods = require('../../utils/methods');
const app = getApp();


Page({
  data: {
    winWidth: 0,
    winHeight: 0,
    imgUrl: [],
    uname:'',
    // tab切换
    currentTab: 0,
    info: {},
    areas: [],
    types: [],
    levels: []
  },


  onLoad(option) {
    let _this = this;
    console.log('传过来的id===', option.id)

    _this.setData({
      areas: app.globalData.areaArray,
      types: app.globalData.typeArray,
      levels: app.globalData.levelArray,
      uname:app.globalData.userInfo.name
    })


    getEventInfo(option.id).then((res) => {
      let img = res[1].fileUrl.split(',');

      //数据处理
      let area = res[1].eventArea;
      let type = res[1].eventType;
      let level = res[1].eventLevel;

      area = (_this.data.areas.find( t => t.value == area)).label;
      type = (_this.data.types.find( t => t.value == type)).label
      level = (_this.data.levels.find( t => t.value == level)).label
      console.log('1=====',area,type,level);

      _this.setData({
        info: res[1],
        imgUrl: img,
        area,
        type,
        level
      }, () => {
        console.log('-----------', _this.data.info)
        console.log('-----------', _this.data.areas)
        console.log('-----------', _this.data.types)
        console.log('-----------', _this.data.levels)
      })
    })
    wx.getSystemInfo({
      success: function (res) {
        _this.setData({
          clientHeight: res.windowHeight
        });
      }
    })
  },

  bindChange: function (e) {
    console.log("滑动切换会触发的事件")
    var _this = this;
    _this.setData({
      currentTab: e.detail.current
    });
  },
  swichNav: function (e) {
    console.log("点击上方选项卡触发的事件")
    var _this = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      _this.setData({
        currentTab: e.target.dataset.current
      })
    }
  }
})